package com.qishon.pc.domain.service;

import com.qishon.pc.domain.model.ProgressControl;
import com.qishon.pc.domain.util.RenderUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by yongwei.chen on 2017/1/4.
 */
@Component
@Slf4j
@RabbitListener(queues = "renderReceiver")
public class RenderReceiverService {
    @Value("${run.path}")
    private String filePath;
    @Value("${maya.script.file}")
    private String mayaPath;

    @Value("${run.maya.file}")
    private String mayaFile;
    @Autowired
    ProgressControlService progressControlService;

    @Autowired
    private RenderUtil renderUtil;

    @RabbitHandler
    public void render(String msg){
        log.info("renderReceiver:" + msg);
        String[] str=msg.split(",");
        int id=Integer.parseInt(str[1]);
        ProgressControl progressControl=progressControlService.findById(id);
        System.out.println("renderReceiver 当前时间："+new Date());
        System.out.println("renderReceiver message："+msg);
        try {
            renderUtil.writeScriptFile(filePath,mayaPath,progressControl,mayaFile);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
